package com.hiyee.goods.service.impl;

import com.github.pagehelper.PageHelper;
import com.hiyee.goods.mapper.CommentMapper;
import com.hiyee.goods.service.CommentService;
import com.hiyee.pojo.GoodsComment;
import com.hiyee.response.PagedGridResult;
import com.hiyee.utils.PageGridResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * 商品信息业务接口
 *
 * @author WangBin
 */
@Service
public class CommentServiceImpl implements CommentService {

    @Autowired
    private CommentMapper commentMapper;

    @Override
    public PagedGridResult getList(Long goodsId, Integer page, Integer pageSize) {
        Example example = new Example(GoodsComment.class);
        example.setOrderByClause("created_at desc");
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("goodsId", goodsId);
        List<GoodsComment> commentList = commentMapper.selectByExample(example);
        PageHelper.startPage(page, pageSize);
        return PageGridResultUtil.getPageGridResult(commentList, page);
    }
}
